package com.bdqn.servlet.Department;

import com.bdqn.entity.CheckWork;
import com.bdqn.entity.Employee;
import com.bdqn.entity.PageBean;
import com.bdqn.service.DepartmentService;
import com.bdqn.service.Impl.DepartmentServiceImpl;
import com.bdqn.util.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "EmpPageQueryServlet",urlPatterns = "/EmpPageQuery")
public class EmpPageQueryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String strdepId = request.getParameter("depId");
        String like_name = request.getParameter("like_name");
        int depId= 0;
        if(strdepId!=null && strdepId.length()>0&& !"null".equals(strdepId)){
            depId = Integer.parseInt(strdepId);
        }
        String strcurrentPage = request.getParameter("currentPage");
        int currentPage = 1;
        if(strcurrentPage!=null && strcurrentPage.length()>0 && !"null".equals(strcurrentPage)){
            currentPage = Integer.parseInt(strcurrentPage);
        }
        String strpageSize = request.getParameter("pageSize");
        int pageSize = 1;
        if(strpageSize!=null && strpageSize.length()>0 && !"null".equals(strpageSize)){
            pageSize = Integer.parseInt(strpageSize);
        }
        DepartmentService service = new DepartmentServiceImpl();
        PageBean<CheckWork> pb = service.pageQuery(depId,like_name,currentPage,pageSize);
        JSON.writeAsString(pb,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
